Plex.Lib.CSS.load('UI.Input.Context');

Plex.UI.Input.Context = function(obj)
{
	var self = this;
	
	this.obj = obj;
	this.actions = new Array();

	this.el = {};
	this.el.menuDiv = new Element('div',{
		'class':'Context'
	})
	
	
	this.addOption = function(title,action,image,atTop)
	{
		var option = {el:{}}
		
		option.el.table = new Element('table',{
			'events':{
				'click': function(){
					action?action():void(1);
				}
			},
			'cellspacing':0,
			'cellpadding':0,
		});
		
		option.el.row = new Element('tr').injectInside(option.el.table);
		option.el.leftCol = new Element('td').injectInside(option.el.row);
		option.el.rightCol = new Element('td').setText(title).injectInside(option.el.row);
		option.el.icon = new Element('img',{
			'src': '/img/silk/' + (image ? image : 'bullet_blue') + '.png'
		}).injectInside(option.el.leftCol);
		
		if(atTop)
		option.el.table.injectTop(self.el.menuDiv);
		else
		option.el.table.injectInside(self.el.menuDiv);
		
	}
	
	this.addBreak=function(atTop)
	{
		var brk = new Element('hr');
		
		if(atTop)
		brk.injectTop(self.el.menuDiv);
		
		
		if(atBeginning)
		nf_IB(contextMenu.childNodes[0],nf_E('hr'))
		else
		nf_A(contextMenu,nf_E('hr'));
	}

	this.showContext=function(ev)
	{
		self.el.menuDiv.injectInside(document.body);
		self.el.menuDiv.style.left=ev.clientX + window.scrollX + "px";
		self.el.menuDiv.style.top=ev.clientY + window.scrollY + "px";
		document.onclick=function(){
			Plex.S$.remove(self.el.menuDiv)
			document.onclick=function(){}
		}

		setTimeout(function()	{
			if(self.el.menuDiv.parentNode)
			{
				Plex.S$.remove(self.el.menuDiv);
				document.onclick=function(){};
			}
		},75000)
	}


	this.build=function()
	{
		self.obj.oncontextmenu=function(ev)
		{
			ev.stopPropagation();
			self.showContext(ev);
			return false;
		}
	}

	this.build();
}